home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
os2
/
srefv12i.zip
/
postmail.80
< prev
next >
Wrap
Text File
|
1997-02-28
|
12KB
|
341 lines
/* a sample of a SRE-FILTER "post-filter"
This will mail a message to selected users, depending on the value
of the request selector, or the client's IP address.
For general notes on how POSTFILT is called, see the bottom of this file.
----------------------- A Mail Notification Facility ----------------
This will automatically send "e-mail alerts" to specified recipients given specified events.
It calls the SREF_MAILIT procedure.
It requires that a valid SMTP Gateway be available (the SMTP Gateway
is set by running SRE-FILTER's configurator and modifying the SMTP_GATEWAY variable)
Note that if you may be able to use OS/2's SENDMAIL program to use the server as
an SMTP gateway (see the TCP/IP command reference documentation).
To use this routine, you will need to set up an "event" list. The event list
should contain the following information:
a) What type of event to examine (client or request selector)
b) The value that triggers a "match" (i.e.; a client's address, or a request for a particular file)
c) The list of e-mail addresses to send "e-mail alerts" to
d) An optional message to include in these alerts.
e) An optional subject line
This routine uses the EVENTS.field.n stem variable to store this event list.
field should take one of 4 values
a)TYPE : Either CLIENT or REQUEST (REQUEST is the "request selector")
b)VALUE : A numeric IP address, or a target request selector. Either may contain * characters;
(either as domain wildcards or to signal "abbreviation matches")
c)RECIPIENTS: A space delimited list of e-mail addresses
d)MESSAGE : An optional message. It may contain CRLFs, and be quite long.
e)SUBJECT: An optional 1 line message to use as the SUBJECT.
n is an integer value (that should run from 1.. "# of events")
You also must set EVENTS.0 equal to the "# of events"
The algorithim works by:
From m=1.. to EVENTS.0
If EVENTS.TYPE.m=CLIENT, then see if client's numeric IP address
matches EVENTS.VALUE.m (with * acceptable as a wildcard)
If EVENTS.TYPE.m=REQUEST, see if the client's request selector matches EVENTS.VALUE.m,
(with * signalling that abbreviation matching should be used).
NOTE: The SEL variable contains the original request selector, before modifications
by SRE-FILTER. The match is against the entire request selector,
not just the Action! Thus, a SEL of FOO.HTM?this_one
will NOT match a target of FOO.HTM (but will match FOO.HTM*)
In comparision, exact matches (say,
in the access_file) compare the action to the target -- so
any ?xxx is ignored.
If either occurs
Create a note containing time,date, server name, client's name, SRE-FILTER status
message, and EVENTS.MESSAGE.m
Note that EVENTS.MESSAGE.m is optional.
If EVENTS.SUBJECT.j is missing, a generic subject line is used.
Sent this note to each e-mail addresss listed in EVENT.RECIPIENTS.m
If there is not SMTP_GATEWAY specified, or EVENTS.0=0, then a short
synopsis of the request is displayed using SAY
Note that there may be multiple matches; so that several different e-mail alerts (to
different sets of e-mail addresses, some of which may contain common
addresses) may be generated by each call to this routine.
Example:
EVENTS.0=3
EVENTS.TYPE.1="CLIENT"
EVENTS.VALUE.1="*.*.*.*"
EVENTS.RECIPIENTS.1="bob@hisorg.net jill@staff.agency.gov "
Note that EVENTS.MESSAGE.1 is not set
EVENTS.TYPE.2="REQUEST"
EVENTS.VALUE.2="PROJECTS/PROJ1.HTM"
EVENTS.RECIPIENTS.2="ANDREW@myorg.org"
EVENTS.MESSAGE.2="A request for PROJ1 was recieved "
events.subject.2=' PROJ1 Request '
EVENTS.TYPE.3="REQUEST"
EVENTS.VALUE.2="\PUT_FILE*"
EVENTS.RECIPIENTS.3="WEBMASTER@MYORG.ORG"
EVENTS.MESSAGE.3="A file upload has been recieved! "||crlf||" You may want to check it?"
Note the use of CRLF to add a line feed to the message.
Note when EVENTS.TYPE.m=REQUEST:
all / are converted to \ (in both the SEL and EV*ENTS.VALUE.n), and
leading and trailing \ are stripped
--------------------------------------------------
*/
postfilt:
CRLF = '0d0a'x
/* ============== INSERT EVENTS list here ================ */
events.0=0
/* ============ DO NOT CHANGE BELOW HERE ===================== */
/* args sent here:
post_filter_message,source0,request0,seloriginal,tempfile,
servername,HOST_NICKNAME,used_file,thereferer,tcache
*/
parse arg amessage,source,request,sel,tempfile,servername,host_nickname,used_file,thereferer
parse var source serveraddr serverport transaction_number clientaddr clientport
GATEWAY=' '
AFF='SREF_'||SERVERPORT||'_SMTP_GATEWAY'
IF HOST_NICKNAME<>' ' THEN do
AFF2=AFF2||'.'||HOST_NICKNAME
GATEWAY=VALUE(AFF2,,'OS2ENVIRONMENT')
end
IF GATEWAY=' ' THEN
GATEWAY=VALUE(AFF,,'OS2ENVIRONMENT')
if gateway=0 then do /* if no gateway specified, do nothing */
call say_stuff
return ' '
end
if events.0=0 then do
call say_stuff
return ' '
end
sname=servername
/* sname=servername() info used below */
cname=clientname()
/* create ip number lookup table */
isnumip=verify(cNAME,'1234567890.')
if isnumip>0 then do /* is numeric ip */
astat=sockgethostbyaddr(clientaddr,'stuff.!')
cname=upper(stuff.!name)
if abbrev(cname,'STUFF.!')=1 then cname=clientaddr
end
atime=time()
adate=date()
CRLF = '0d0a'x
/* loop through events list .. */
didit=0
do jj=1 to events.0
ok=0
if events.TYPE.jj="CLIENT" then
ok=goodip(events.VALUE.jj,clientaddr)
else
if events.type.jj='REQUEST' then do
ok=goodsel(upper(events.value.jj),upper(sel))
end
if ok=0 then iterate
if didit=0 then
call pmprintf(" Using gateway at " gateway)
didit=1
/* if here, a match occurred */
address_list=events.recipients.jj
if symbol('events.subject.jj')='VAR' then
asubject='Subject: '||events.subject.jj
else
asubject='Subject: Notification of WEB transaction '
themessage="Date: " || adate || ' ' ||atime
themessage=themessage||crlf||'From: WebServer@'||sname
themessage=themessage||crlf||asubject
themessage=themessage||crlf||'To: '||address_list||crlf
themessage=themessage||crlf||'An e-mail alert from the Web Server at '||sname
themessage=themessage||crlf||" Date of occurrence: " || adate || ' ' ||atime
themessage=themessage||crlf||' Request by client: '|| cname
themessage=themessage||crlf||' Request selector: '|| sel
themessage=themessage||crlf||' Server status message: '|| amessage
if symbol('events.message.jj')='VAR' then /* check for a mess up */
themessage=themessage||crlf||"Notes:"||crlf||events.message.jj||crlf
else
themessage=themessage||crlf
foo=sref_mailit(address_list,themessage, gateway)
call pmprintf(" Event " jj ", MAILIT status: "foo)
end /* try next event */
return ' '
/* -----------------------------------------------------------------------*/
/* see if match (or abbreviation match) the sel */
/* -----------------------------------------------------------------------*/
goodsel: procedure
parse arg asel,thesel
asel=translate(asel) ; thesel=translate(thesel)
asel=translate(asel,'\','/') ; asel=strip(asel,,'\')
thesel=translate(thesel,'\','/') ; thesel=strip(thesel,,'\')
if asel=thesel then return 1 /* exact match */
/* do abbreviation match? */
if right(asel,1)<>'*' then return 0 /* nope */
asel=left(asel,length(asel)-1) /* try an abbreviation match */
return abbrev(strip(thesel),strip(asel))
/* -----------------------------------------------------------------------*/
/* see if matches one of a set of good ips (1 if yes)*/
/* -----------------------------------------------------------------------*/
goodip: procedure
parse arg anips,cip0
parse var anips ip.1 '.' ip.2 '.' ip.3 '.' ip.4
parse var cip0 cip.1 '.' cip.2 '.' cip.3 '.' cip.4
match=1
do mm2=1 to 4
if ip.mm2="*" then iterate
if ip.mm2=cip.mm2 then iterate
match=0 /*if here, not a match */
leave
end
return match
/* A simple transaction recorder (used if no SMTP_GATEWAY specified */
say_stuff:
say " - - - - - "
say time() ' ' date()
say " Message= " amessage
say " Source= " source
say " Request= " request
say " Sel = " sel
return
/*******************************************************************
*******************************************************************
*******************************************************************/
/*
---------------- General notes ------------------------
SRE-FILTER call this procedure when the POST_FILTER variable is set to YES.
6 arguments are passed here:
amessage
source
request
sel0
tempfile
params
Amessage
is generated by SRE-FILTER, and indicates what SRE-FILTER did with this request.
Source,request,and sel0 are generated by GoServe, and contain:
Source
serveraddr serverport transaction_number clientaddr clientport
Request
verb uri protocol
Sel0
action '?' awords (?awords may not be present
Tempfile is set in SRE-FILTER
Tempfile
A temporary file name. It may have been used to construct the response, so you probably should
delete it first (use SYSFILEDELETE(TEMPFILE) ).
Params
Are optional parameters sent by SRE-FILTER. Currently, it contains the name of the
SMTP gateway (set in the SMTP_GATEWAY variable of SRE-FILTER).
Example:
message HTML File sent:/INDEX.HTM
Source 151.121.65.143 80 3 219.134.78.12 1026
request GET /sampask2.htm HTTP/1.0
sel0 sampask2.htm
tempfile D:/GOHTTP/$10.80
params mail.myprovider.net
Note on Amessage:
The folllowing lists the "messages" that SRE-FILTER may send. Note that the ||varname
means the value of Varname is appended to the message. Also note that when varname=SEL,
the SEL may be different then SEL0 (say, if a ~ replacement occurred).
Pre-filter used
Cached file sent: ||sel0
Bad HTTP Protocol
Unauthorized access
No client name found, access denied
Logon denied to non-inhouse user
Pre-filter used
Alias invoked permanent redirect
Alias invoked temporary redirect
Transfered non-data directory file
Access to file denied: ||sel
Ping request
CONTROL Statistics request
Host request
Control Moveaudit
Control Reset all
Variable display
!Special request denied: ||sel
Message box access
Message box access denied
Message box viewing
Special request processing unknown:||sel
HEAD request: Document not found: ||sel0
Head request
Document not found
Server is busy
Non-HTML File sent:||file
HTML File sent:||file
HTML File sent (with ssi):||file
Mappable image request:'||foo
GET request:||action
Server busy
POST error: too much data
POST error: could not read data
POST request:||sel
POST problem:||sel
CGI-BIN access||sel
**************************************************************************/